import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home.vue'
import Mine from '../views/mine.vue'
import Card from '../views/card.vue'
import Money from '../views/money.vue'
import Pick from '../views/pick.vue'
import Transfer from '../views/transfer.vue'
import Login from '../views/login.vue'
import Defray from '../views/defray.vue'
import Deposit from '../views/deposit.vue'
// 二级路由
import Headlines from '../views/Level 2/headlines.vue'
import Headline2 from '../views/Level 2/headline2.vue'
import Headline3 from '../views/Level 2/headline3.vue'
import Headline4 from '../views/Level 2/headline4.vue'
import Headline5 from '../views/Level 2/headline5.vue'

import No from '../views/no.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
  },
  {
    path: '/mine',
    name: 'Mine',
    component: Mine
  },
  {
    path: '/card',
    name: 'Card',
    component: Card
  },
  {
    path: '/money',
    name: 'Money',
    component: Money
  },
  {
    path: '/pick',
    name: 'Pick',
    component: Pick
  },
  {
    path: '/transfer',
    name: 'Transfer',
    component: Transfer,
    children: [
      {
        path: '/',
        redirect: '/headlines'
      },
      {
        path: '/headlines',
        name: 'Headlines',
        component: Headlines,
      },
      {
        path: '/headline2',
        name: 'Headline2',
        component: Headline2,
      },
      {
        path: '/headline3',
        name: 'Headline3',
        component: Headline3,
        beforeEnter(to,from,next){
      alert("你还没有登录，请登录后访问！！！")
     
      console.log(to);
      console.log(from);
      next("/login")
    }
      },
      {
        path: '/headline4',
        name: 'Headline4',
        component: Headline4,
        beforeRouteLeave(to,from,next){
        console.log(to);
        console.log(from);
        if(confirm("您确定离开phone吗？")){
            next()
        }else{
            // 不跳转
            next(false)
        }
    }
      },
      {
        path: '/headline5',
        name: 'Headline5',
        component: Headline5,
      },
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/defray',
    name: 'Defray',
    component: Defray
  },
  {
    path: '/deposit',
    name: 'Deposit',
    component: Deposit,

  },
  {
    path: '*',
    name: 'No',
    component: No
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
